package com.sponsorpay.sdk.android.advertiser;

import android.os.AsyncTask;
import com.sponsorpay.sdk.android.credentials.SPCredentials;
import com.sponsorpay.sdk.android.utils.SPHttpClient;
import com.sponsorpay.sdk.android.utils.SponsorPayLogger;
import com.sponsorpay.sdk.android.utils.StringUtils;
import com.sponsorpay.sdk.android.utils.UrlBuilder;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;

public abstract class AbstractCallbackSender extends AsyncTask<String, Void, Boolean>
{
  private static final String INSTALL_SUBID_KEY = "subid";
  protected static final int SUCCESFUL_HTTP_STATUS_CODE = 200;
  protected static final String SUCCESSFUL_ANSWER_RECEIVED_KEY = "answer_received";
  private SPCredentials mCredentials;
  private Map<String, String> mCustomParams;
  protected SponsorPayAdvertiserState mState;

  public AbstractCallbackSender(SPCredentials paramSPCredentials, SponsorPayAdvertiserState paramSponsorPayAdvertiserState)
  {
    this.mState = paramSponsorPayAdvertiserState;
    this.mCredentials = paramSPCredentials;
  }

  private String buildUrl()
  {
    Object localObject = getParams();
    if (localObject == null)
      localObject = new HashMap();
    if (this.mCustomParams != null)
      ((Map)localObject).putAll(this.mCustomParams);
    ((Map)localObject).put("answer_received", getAnswerReceived());
    String str1 = this.mState.getInstallSubId();
    if (StringUtils.notNullNorEmpty(str1))
      ((Map)localObject).put("subid", str1);
    String str2 = UrlBuilder.newBuilder(getBaseUrl(), this.mCredentials).addExtraKeysValues((Map)localObject).sendUserId(false).addScreenMetrics().buildUrl();
    SponsorPayLogger.d(AbstractCallbackSender.class.getSimpleName(), "Callback will be sent to: " + str2);
    return str2;
  }

  protected Boolean doInBackground(String[] paramArrayOfString)
  {
    HttpGet localHttpGet = new HttpGet(paramArrayOfString[0]);
    HttpClient localHttpClient = SPHttpClient.getHttpClient();
    try
    {
      HttpResponse localHttpResponse = localHttpClient.execute(localHttpGet);
      int i = localHttpResponse.getStatusLine().getStatusCode();
      localHttpResponse.getEntity().consumeContent();
      if (i == 200);
      Boolean localBoolean2;
      for (Object localObject = Boolean.valueOf(true); ; localObject = localBoolean2)
      {
        SponsorPayLogger.d(AbstractCallbackSender.class.getSimpleName(), "Server returned status code: " + i);
        return localObject;
        localBoolean2 = Boolean.valueOf(false);
      }
    }
    catch (Exception localException)
    {
      Boolean localBoolean1 = Boolean.valueOf(false);
      SponsorPayLogger.e(AbstractCallbackSender.class.getSimpleName(), "An exception occurred when trying to send advertiser callback: " + localException);
      return localBoolean1;
    }
  }

  protected abstract String getAnswerReceived();

  protected abstract String getBaseUrl();

  protected abstract Map<String, String> getParams();

  protected void onPostExecute(Boolean paramBoolean)
  {
    processRequest(paramBoolean);
  }

  protected abstract void processRequest(Boolean paramBoolean);

  public void setCustomParams(Map<String, String> paramMap)
  {
    this.mCustomParams = paramMap;
  }

  public void trigger()
  {
    String[] arrayOfString = new String[1];
    arrayOfString[0] = buildUrl();
    execute(arrayOfString);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.sponsorpay.sdk.android.advertiser.AbstractCallbackSender
 * JD-Core Version:    0.6.2
 */